//
//  LottieWrapper.swift
//  us
//
//  Created by karry on 2025/3/29.
//

import Lottie
import UIKit
 

@objc @MainActor class LottieWrapper: NSObject {
    
    @objc var animationView: LottieAnimationView?

    @objc init(name: String) {
        self.animationView = LottieAnimationView(name: name)
        super.init()
    }

    @objc func setFrame(_ frame: CGRect) {
        animationView?.frame = frame
//        animationView?.contentMode = .scaleAspectFit  // 适应大小

    }

    @objc func addToView(_ view: UIView) {
        if let animationView = animationView {
            view.addSubview(animationView)
        }
    }

    @objc func playAnimation() {
        animationView?.play()
    }

    @objc func setLoop(_ loop: Bool) {
        animationView?.loopMode = loop ? .loop : .playOnce
    }
    
    /// **获取动画时长**
     @objc func getAnimationDuration() -> CGFloat {
         return animationView?.animation?.duration ?? 0.0
     }
}
